<?php
	include $_SERVER['DOCUMENT_ROOT'].'/core/'.'core.php';

	$resArray = array();// массив результата
	Auth::logout();
	/* если не logout - authentication и checkUser */
	if( empty($_REQUEST['logout'])){ 
	
		$form_name='login_form_';
		$result = array();
		
		Auth::authentication();
		Auth::checkUser();
		
		$values = Form::valuesAll( $form_name ) ;
		if( count($values)>0 ) foreach( $values as $name=>$value ) $result['values'][$name]=$value;
		
		$errors = Form::errorsAll( $form_name ) ;
		if( count($errors)>0 ) foreach( $errors as $name=>$value ) $result['errors'][$name]=$value;
		else foreach( $_SESSION['user'] as $name=>$value ) //if( strstr($name, 'ud_') ) 
		$result['user'][$name]=$value;

		$resArray[ $form_name.'data' ] = array('data'=>$result, 'desc'=>'данные для '.$form_name);
	}
	
	$login_panel_out = Page::outModules( '<!--Module::CoreModule({"template_name":"login_panel.php"})-->' );
	$login_form_out = Page::outModules( '<!--Module::Auth()-->' );
	/* обновление модуля login_panel */
	$resArray[ 'out_data' ] = array(
		'login_panel'=>$login_panel_out,
		//'debug'=>'$parse_url ='.print_r(Page::parse_url( $_SERVER['REQUEST_URI'] ), true),
		//'login_form'=>$login_form_out,
	);

	echo json_encode( $resArray );
?>